package com.ayf.payment.game.api.service.platform.impl;

import com.ayf.payment.game.api.config.SystemInitialization;
import com.ayf.payment.game.api.dto.platform.SettleConfigDTO;
import com.ayf.payment.game.api.entity.platform.SettleConfig;
import com.ayf.payment.game.api.mapper.platform.SettleConfigMapper;
import com.ayf.payment.game.api.service.platform.SettleConfigService;
import com.swwx.charm.commons.lang.utils.BeanConvertUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SettleConfigServiceImpl implements SettleConfigService {

    @Resource
    private SettleConfigMapper settleConfigMapper;
    @Resource
    private SystemInitialization systemInitialization;

    @Override
    public void updateSettleConfig(SettleConfigDTO settleConfigDTO) {
        settleConfigMapper.updateByPrimaryKeySelective(BeanConvertUtils.convert(settleConfigDTO, SettleConfig.class));
        systemInitialization.initSettleConfig();
    }

    @Override
    public SettleConfigDTO getSettleConfig() {
        if(systemInitialization==null || systemInitialization.settleConfigDTO()==null) {
            return BeanConvertUtils.convert(settleConfigMapper.getSettleConfig(), SettleConfigDTO.class);
        }else{
            return systemInitialization.settleConfigDTO();
        }
    }

}
